/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.javanile.me.chessengine;

/**
 *
 * @author cicciodarkast
 */
public class Square {
	private Node node;
    private int rank;
    private int file;
	private int index;
    
    public Square(int r, int c) {
        rank = r;
        file = c;
		index = c*8+r;
    }
	public Square(int i, Node n) {
		node = n;
	    rank = i%8;
        file = i/8;   
		index = i;
	}
    public Square(String s) {
        rank = 56-s.charAt(1);
        file = s.charAt(0)-97;
		index = file*8+rank;
    }
    public int getRank() {
        return rank;
    }
    public int getFile() {
        return file;
    }
    public Square shift(int dr,int dc) {
        return new Square(rank+dr,file+dc);
    }
    public Square shift(int[] d) {
        return new Square(rank+d[0],file+d[1]);
    }
	/*
	public boolean isWhiteSquare() {
		return node.isWhiteSquare();
	}
	public boolean isBlackSquare() {
		return node.isBlackSquare();
	}
	 * 
	 */
	public int getValue() {
		return Constants.SQUARE_VALUE[index];
	}
    public String toString() {
        return ""+((char)(file+97))+((char)(56-rank));
    }
	public static String toString(int square) {
		int file = (square%12)-2;
		int rank = (square/12)-2;
		return toString(file,rank);
	}
	public static String toString(int file, int rank) {
		return ""+((char)(file+97))+((char)(56-rank));
	}
	
	public static int toInt(String s) {
		return (s.charAt(0)-95)+(58-s.charAt(1))*12;
	}
}
